import {
	TreeExpViewActionType,
	ITreeExpViewAbility,
	ITreeExpViewControllerParams,
	ITreeExpViewModel,
	ITreeExpViewStore,
	IParam,
	IViewEvent,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getViewClassNames,
	handleQuickGroupValueChange,
	initExpViewSplit,
	setExpViewSplit,
	useViewAction,
	useViewBasic,
	useViewControllerParams,
	useViewProps,
} from '../use-view';

/**
 * 获取树导航视图输入参数
 *
 * @export
 * @return {*}
 */
export function useTreeExpViewProps() {
	return {
		...useViewProps(),
	};
}

/**
 * 获取树导航视图基础
 *
 * @export
 * @param {ITreeExpViewModel} model 树导航视图模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useTreeExpViewBasic(model: ITreeExpViewModel,props: IParam) {
	const getClassNames = (props:IParam) =>{
		const classNames = getViewClassNames(model, props);
		Object.assign(classNames, {'deexpview': true});
		return classNames; 
	}
	const initSplit = (instance: any) => {
		if (instance && instance.vnode && instance.vnode.el) {
			return initExpViewSplit(instance.vnode.el as HTMLElement, model) || 0.15;
		}
	}
	const handleSplitChange = (model: any,split: number) => {
		setExpViewSplit(model, split);
	}
	return {
		...useViewBasic(model,props),
		getClassNames,
        initSplit,
		handleSplitChange,
		handleQuickGroupValueChange
	};
}

/**
 * 树导航视图行为
 *
 * @export
 */
export function useTreeExpViewAction(controller: any) {
	return {
		...useViewAction(controller),
	};
}

/**
 * 获取树导航视图控制器输入参数
 *
 * @export
 * @param {ITreeExpViewModel} model
 * @param {IParam} props
 * @param {QXEvent<IViewEvent<TreeExpViewActionType, ITreeExpViewAbility>>} evt
 * @return {*}  {ITreeExpViewControllerParams<TreeExpViewActionType, ITreeExpViewAbility>}
 */
export function useTreeExpViewControllerParams(
	model: ITreeExpViewModel,
	props: IParam,
	evt: QXEvent<IViewEvent<TreeExpViewActionType, ITreeExpViewAbility>>
): ITreeExpViewControllerParams<TreeExpViewActionType, ITreeExpViewAbility> {
	return {
		...useViewControllerParams<ITreeExpViewStore, ITreeExpViewModel>(
			model,
			props,
			evt
		),
	};
}
